home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!falstaff
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.lang.c
- Subject: Re: routine for yesterday's date
- Date: 3 Apr 1996 14:27:44 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4ju1t0$p2q@news.xs4all.nl>
- References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com> <Dp3B56.FKI@alisa.org> <1996Mar31.062512.22480@sq.com> <31614471.2351449@ottnews.shl.com>
- NNTP-Posting-Host: xs1.xs4all.nl
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- 75323.455@compuserve.com (Bruce Coghill) writes:
-
- >Anyway, I did manage to implement a solution using similar code from
- >this thread from user (Falstaff). It compiles and I will be testing
- >it today, I hope :~+
-
- >/*******************************************/
- >int DIM[12]={31,28,31,30,31,30,31,31,30,31,30,31};
-
- >if(!--d)
- >{
- > if(!--m)
- > { m=12;
- > y--; }
-
- > DIM[1]=(~y&3 && (y%100||!(y%400)))?29:28; /* See note below */
- > d=DIM[m-1];
- >}
- >/***************************************/
-
- >The DIM[1]= line I understand everything after the &&, however not
- >before. I know the unary (~), logical (&) and the other and (&&), but
- >why to we and the year with 3 then change the bits?
-
- I wasn't thinking clearly there... I should have written
-
- DIM[1]=(y%4==0 && (y%100||!(y%400)))?29:28;
-
- ~y&3 evaluates to nonzero if y=3,7,11... etc. That's nice for
- some things, but not here.
- The expression before the ? breaks up as follows:
-
- y%4==0 year a multiple of four
- && and
- ( y%100 it is not a multiple of 100
- || or
- !(y%400) it is a multiple of 400
- )
-
- This all means that DIM[1] is set to 29 if above conditions hold (when
- it's a leap year) and to 28 if they dont.
-
- Falstaff
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-